#!/bin/bash

git_host="https://github.com"
tmp_log="_logs/tmp_repos.log"
pre_log="_logs/pre_repos.log"
user=""	# 要克隆的用户名

function gitclone() {
    username=$1
    if [ -f $tmp_log ];then
	rm $tmp_log
    fi
    touch $tmp_log


    
    for i in  {1..2} ## 需要根据github上实际有几页自行设定  
    do
	echo "$i"
        curl "$git_host/$username?page=$i" | grep codeRepository | grep -oP '(?<=href=").*?(?=")' >> $tmp_log
    done

    cat $tmp_log | while read line
    do
	name=$(basename $line)	# 找到仓库名
	echo $git_host$line.git
	git clone $git_host$line.git
    done
    
    # TODO compare pre_log and tmp_log
    mv $tmp_log $pre_log
}

gitclone $user
